package com.czl.module_storehouse.mvp.presenter;

import com.czl.base.data.bean.tengyun.BorrowBean;
import com.czl.base.data.bean.tengyun.ReceiveBean;
import com.czl.base.data.bean.tengyun.RecordRemandBean;
import com.czl.module_base.bean.ListBean;
import com.czl.module_base.http.HttpResponse;
import com.czl.module_base.mvp.presenter.BasePresenter;
import com.czl.module_base.observer.AbsHandleSubscriber;
import com.czl.module_storehouse.bean.BorrowReturnBean;
import com.czl.module_storehouse.bean.ReceiveReturnNeedBean;
import com.czl.module_storehouse.bean.RemandReturnBean;
import com.czl.module_storehouse.mvp.model.RemandHomeModel;
import com.czl.module_storehouse.mvp.view.RemandHomeView;

/**
 * @author xubin
 */
public class RemandHomePresenter extends BasePresenter<RemandHomeModel, RemandHomeView> {

    public static final String TAG_REMAND_DIRECT_RETURN = "remand_direct_return";
    public static final String TAG_REMAND_RECEIVE = "remand_receive";
    public static final String TAG_REMAND_BORROW = "remand_borrow";

    /**
     * 领用归还
     *
     * @param bean
     */
    public void receiveReturn(ReceiveReturnNeedBean bean) {

        doSubscribe3(mModel.receiveReturn(bean), new AbsHandleSubscriber<HttpResponse<Object>>() {
            @Override
            public void onSuccess(HttpResponse<Object> listHttpResponse) {
                listHttpResponse.setRequestTag(TAG_REMAND_RECEIVE);
                mView.showHttpResponse(listHttpResponse);
            }
        });
    }

    /**
     * 借用归还
     *
     * @param bean
     */
    public void borrowReturn(BorrowReturnBean bean) {
        doSubscribe3(mModel.borrowReturn(bean), new AbsHandleSubscriber<HttpResponse<Object>>() {
            @Override
            public void onSuccess(HttpResponse<Object> listHttpResponse) {
                listHttpResponse.setRequestTag(TAG_REMAND_BORROW);
                mView.showHttpResponse(listHttpResponse);
            }
        });
    }

    /**
     * 借用归还
     *
     * @param bean
     * @param requestTag
     */
    public void directReturn(RemandReturnBean bean, int requestTag) {
        doSubscribe3(mModel.directReturn(bean), new AbsHandleSubscriber<HttpResponse<Object>>() {
            @Override
            public void onSuccess(HttpResponse<Object> listHttpResponse) {
                listHttpResponse.setRequestTag(TAG_REMAND_DIRECT_RETURN);
                mView.showHttpResponse(listHttpResponse);
            }
        });
    }

    public void getSortUseInfo(boolean refresh, String userName, Integer sortId) {
        resetPageNo(refresh);
        doSubscribe(mModel.getSortUseInfo(userName, sortId, mPageNo), new AbsHandleSubscriber<HttpResponse<ListBean<RecordRemandBean>>>() {
            @Override
            public void onSuccess(HttpResponse<ListBean<RecordRemandBean>> httpResponse) {
                mView.showData(httpResponse.getData());
                nextPageNo();
            }
        });
    }

    public void getProUseInfo(String userName, String sortName) {

        doSubscribe(mModel.getProUseInfo(userName, sortName), new AbsHandleSubscriber<HttpResponse<ListBean<RecordRemandBean>>>() {
            @Override
            public void onSuccess(HttpResponse<ListBean<RecordRemandBean>> httpResponse) {
                mView.showData(httpResponse);
            }
        });
    }

    public void getProUseInfo(boolean refresh, String searchName, boolean loading) {
        resetPageNo(refresh);
        doSubscribe(mModel.getProUseInfo(searchName, mPageNo), new AbsHandleSubscriber<HttpResponse<ListBean<RecordRemandBean>>>() {
            @Override
            public void onSuccess(HttpResponse<ListBean<RecordRemandBean>> httpResponse) {
                mView.showData(httpResponse.getData());
                nextPageNo();
            }
        }, loading);
    }

    public void getDamageSortList(boolean refresh, String searchName) {
        resetPageNo(refresh);
        doSubscribe(mModel.getDamageSortList(searchName, mPageNo), new AbsHandleSubscriber<HttpResponse<ListBean<RecordRemandBean>>>() {
            @Override
            public void onSuccess(HttpResponse<ListBean<RecordRemandBean>> httpResponse) {
                mView.showData(httpResponse.getData());
                nextPageNo();
            }
        });
    }

    /**
     * 查询待领出领用单
     */
    public void getNeedDealtReceiveList() {
        doSubscribe(mModel.getNeedDealtReceiveList(), new AbsHandleSubscriber<HttpResponse<ListBean<ReceiveBean>>>() {
            @Override
            public void onSuccess(HttpResponse<ListBean<ReceiveBean>> httpResponse) {
                mView.showData(httpResponse);
                mPageNo++;
            }
        });
    }

    /**
     * 查询待归还领用单
     *
     * @param reload
     */
    public void getNeedReturnReceiveList(boolean reload) {
        if (reload) {
            mPageNo = 1;
        }
        doSubscribe(mModel.getNeedReturnReceiveList(mPageNo), new AbsHandleSubscriber<HttpResponse<ListBean<ReceiveBean>>>(mView) {
            @Override
            public void onSuccess(HttpResponse<ListBean<ReceiveBean>> httpResponse) {
                mView.showData(httpResponse.getData());
                mPageNo++;
            }
        });
    }

    public void getReturnReceiveList(boolean reload) {
        if (reload) {
            mPageNo = 1;
        }
        doSubscribe(mModel.getReturnReceiveList(mPageNo),
                new AbsHandleSubscriber<HttpResponse<ListBean<ReceiveBean>>>(mView) {
                    @Override
                    public void onSuccess(HttpResponse<ListBean<ReceiveBean>> httpResponse) {
                        mView.showData(httpResponse.getData());
                        mPageNo++;
                    }
                });
    }

    public void getNeedReturnBorrowList(boolean reload) {
        if (reload) {
            mPageNo = 1;
        }
        doSubscribe(mModel.getNeedReturnBorrowList(mPageNo),
                new AbsHandleSubscriber<HttpResponse<ListBean<BorrowBean>>>(mView) {
                    @Override
                    public void onSuccess(HttpResponse<ListBean<BorrowBean>> httpResponse) {
                        mView.showData(httpResponse.getData());
                        mPageNo++;
                    }
                });
    }

    public void getReturnBorrowList(boolean reload) {
        if (reload) {
            mPageNo = 1;
        }
        doSubscribe(mModel.getReturnBorrowList(mPageNo),
                new AbsHandleSubscriber<HttpResponse<ListBean<BorrowBean>>>(mView) {
                    @Override
                    public void onSuccess(HttpResponse<ListBean<BorrowBean>> httpResponse) {
                        mView.showData(httpResponse.getData());
                        mPageNo++;
                    }
                });
    }
}
